package cn.tedu.blackhorse.controller;

import cn.tedu.blackhorse.pojo.dto.StudentAddNewDTO;
import cn.tedu.blackhorse.pojo.dto.StudentUpdateDTO;
import cn.tedu.blackhorse.pojo.dto.TeacherAddNewDTO;
import cn.tedu.blackhorse.pojo.dto.TeacherUpdateDTO;
import cn.tedu.blackhorse.pojo.vo.StudentListItemVO;
import cn.tedu.blackhorse.pojo.vo.TeacherListItemVO;
import cn.tedu.blackhorse.service.IStudentService;
import cn.tedu.blackhorse.service.ITeacherService;
import cn.tedu.blackhorse.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 处理品牌相关请求的控制器
 *
 * @author java@tedu.cn
 * @version 0.0.1
 */
@Slf4j
@RestController
@RequestMapping("/teacher")
@Api(tags = "老师信息表")
@Validated
public class TeacherController {

    @Autowired
    private ITeacherService teacherService;

    public TeacherController() {
        log.info("创建控制器：TeacherController");
    }


    // http://localhost:9088/teacher/addNew
    @ApiOperation("增加老师信息")
    @ApiOperationSupport(order = 100)
    @ApiImplicitParam(name = "id", value = "老师id", required = true, dataType = "long")
    @PostMapping("/addNew")
    public JsonResult<Void> addNew(TeacherAddNewDTO teacherAddNewDTO) {
        log.debug("开始处理【增加老师信息】的请求");
        teacherService.addNew(teacherAddNewDTO);
        return JsonResult.ok();
    }

    // http://localhost:9088/teacher
    @ApiOperation("老师信息列表")
    @ApiOperationSupport(order = 200)
    @GetMapping("")
    public JsonResult<List<TeacherListItemVO>> list() {
        log.debug("开始处理【老师信息列表】的请求");
        List<TeacherListItemVO> list = teacherService.list();
        return JsonResult.ok(list);
    }

    // http://localhost:9088/teacher/12/delete
    @ApiOperation("删除老师")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "老师id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long id) {
        log.debug("开始处理【删除老师】的请求：id={}", id);
        teacherService.deleteById(id);
        return JsonResult.ok();
    }

    // http://localhost:9088/teacher/update
    @ApiOperation("修改老师信息")
    @ApiOperationSupport(order = 400)
    @ApiImplicitParam(name = "id", value = "老师id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult<Void> update(@PathVariable Long id, TeacherUpdateDTO teacherUpdateDTO) {
        log.debug("开始处理【修改老师信息】的请求");
        teacherService.updateById(id,teacherUpdateDTO);
        return JsonResult.ok();
    }


}
